<?php
namespace app\service;
use think\facade\Log;
use think\facade\Cache;


class BaseService{

    private $success  = true;
    private $code  = 0;
    private $msg  = '成功';
    private $data = [];
    
    public function is_params($params) {
        if(is_array($params)){
            $flag = true;
            if (array_key_exists('success', $params)) {
                $this->success = $params['success'];
                $flag       = false;
            }
            if (array_key_exists('code', $params)) {
                $this->code = $params['code'];
                $flag       = false;
            }
            if (array_key_exists('msg', $params)) {
                $this->msg = $params['msg'];
                $flag       = false;
            }
            if (array_key_exists('data', $params)) {
                $this->data = $params['data'];
            }else{
                if ($flag) {
                    $this->data = $params;
                }
            }
        }else{
            $this->data = $params;
        }
        return [
            'success' => $this->success,
            'code' => $this->code,
            'msg' => $this->msg,
            'data' => $this->data
        ];
    }

    public function return_msg($data=[]){
        $result=$this->is_params($data);
        return json($result);
    }

    public function return_err($data=[]){
        $this->success=false;
        $this->code=1;
        $this->msg='错误';
        $result=$this->is_params($data);
        return json($result);
    }









}
